package com.cskaoyan.service.wx.sl;

import com.cskaoyan.bean.Goods;
import com.cskaoyan.bean.GoodsExample;
import com.cskaoyan.bean.Topic;
import com.cskaoyan.mapper.GoodsMapper;
import com.cskaoyan.mapper.TopicMapper;
import com.cskaoyan.vo.wx.sl.TopicDetailVo;
import com.cskaoyan.vo.wx.sl.WxTopicListDataBean;
import com.cskaoyan.vo.wx.sl.WxTopicListVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxTopicServiceImpl implements WxTopicService {

    @Autowired
    TopicMapper topicMapper;

    @Autowired
    GoodsMapper goodsMapper;
    //显示专题列表
    @Override
    public WxTopicListVo topicList(Integer page, Integer size) {
        //分页排序
        PageHelper.startPage(page, size);
        //查询
        List<WxTopicListDataBean> list = topicMapper.queryListss();
        PageInfo<WxTopicListDataBean> goodsPageInfo = new PageInfo<>(list);//查询结果放进来
        long total = goodsPageInfo.getTotal();//总的数量select count(*)

        WxTopicListVo wxTopicListVo = new WxTopicListVo();
        wxTopicListVo.setData(list);
        wxTopicListVo.setCount(total);
        return wxTopicListVo;
    }
    //显示专题详情
    @Override
    public TopicDetailVo TopicDetail(Integer id) {
        Topic topic = topicMapper.selectByPrimaryKey(id);
        //因为是空设定一个假的,后续可以延伸
        GoodsExample goodsExample = new GoodsExample();
        GoodsExample.Criteria criteria = goodsExample.createCriteria();
        criteria.andNameLike("hahahahahahahah");
        List<Goods> goods = goodsMapper.selectByExample(goodsExample);
        TopicDetailVo topicDetailVo = new TopicDetailVo();
        topicDetailVo.setGoods(goods);
        topicDetailVo.setTopic(topic);
        return topicDetailVo;
    }
    //专题推荐
    @Override
    public Topic topicRelated(Integer id) {
        Topic topic = topicMapper.selectByPrimaryKey(id);
        return topic;
    }

}
